package vinnichenko.lab3.database;

/**Java core packages*/
import java.io.*;
import java.text.*;
import java.util.*;

import org.w3c.dom.*;

/**EmployeeInfo contains the data for one employee.
 * @author Igor Vinnichenko
 * @version 1.0
 */
public class EmployeeInfo implements Serializable {
    /**UID*/
    private static final long serialVersionUID = 1L;

    /**Employee number, Manager's number, Department's number fields*/
    private int empno, mgr, deptno;
    /**Employee's name and Job fields*/
    private String ename, job;
    /**Salary and Commitee fields*/
    private double sal, comm;
    /**Hiredate field*/
    private Date hiredate;
    /**level in hierarchy in company of employee*/
    private int levelInHierarchy;
    /**Manager's name field*/
    private String managerName;
    /**Department's name field*/
    private String deptName;
   
    /**Constructor*/
    public EmployeeInfo(){
        /**Filling all fields with default values*/
        empno = 0;
        mgr = 0;
        deptno = 0;
        ename = "";
        job = "";
        sal = 0.0;
        comm = 0.0;
        hiredate = new Date();
        levelInHierarchy = 0;
        managerName = "";
        deptName="";
    }

    /**Set new employee's number.
     * @param empno new employee's number.
     */
    public void setEmployeeNo( int empno ){
        this.empno = empno;
    }
   
    /**Get employee's number.
     * @return employees number.
     */
    public int getEmployeeNo(){
        return empno;
    }
   
    /**Set new employee's manager.
     * @param empno new employee's manager.
     */
    public void setManager( int mgr ){
        this.mgr = mgr;
    }
   
    /**Get employee's manager.
     * @return employees manager.
     */
    public int getManager(){
        return mgr;
    }
   
    /**Set new employee's department number.
     * @param empno new employee's department number.
     */
    public void setDepartmentNo( int deptno ){
        this.deptno = deptno;
    }
   
    /**Get employee's department number.
     * @return employees department number.
     */
    public int getDepartmentNo(){
        return deptno;
    }
   
    /**Set new employee's name.
     * @param empno new employee's name.
     */
    public void setEmployeeName( String ename ){
        this.ename = ename;
    }
   
    /**Get employee's name.
     * @return employees name.
     */
    public String getEmployeeName(){
        return ename;
    }
   
    /**Set new employee's job.
     * @param empno new employee's job.
     */
    public void setJob( String job ){
        this.job = job;
    }
   
    /**Get employee's job.
     * @return employees job.
     */
    public String getJob(){
        return job;
    }

    /**Set new employee's salary.
     * @param empno new employee's salary.
     */
    public void setSalary( double sal ){
        this.sal = sal;
    }
   
    /**Get employee's salary.
     * @return employees salary.
     */
    public double getSalary(){
        return sal;
    }

    /**Set new employee's commisions.
     * @param empno new employee's commisions.
     */
    public void setCommisions( double comm ){
        this.comm = comm;
    }
   
    /**Get employee's commisions.
     * @return employees commisions.
     */
    public double getCommisions(){
        return comm;
    }

    /**Set new employee's hire date.
     * @param empno new employee's hire date.
     */
    public void setHireDate( Date hiredate ){
        this.hiredate = hiredate;
    }
   
    /**Get employee's hire date.
     * @return employees hire date.
     */
    public Date getHireDate(){
        return hiredate;
    }

    /**Set new employee's hierarchy level.
     * @param empno new employee's hierarhy level.
     */
    public void setLevel( int levelInHierarchy ){
        this.levelInHierarchy = levelInHierarchy;
    }
   
    /**Get employee's hierarchy level.
     * @return employees hierarchy level.
     */
    public int getLevel(){
        return levelInHierarchy;
    }

    /**Get employee's manager's name.
     * @return employees manager's name.
     */
    public String getManagerName(){
        return managerName;
    }

    /**Set new employee's manager's name.
     * @param empno new employee's manager's name.
     */
    public void setManagerName(String managerName){
        this.managerName = managerName;
    }

    /**Get employee's department name.
     * @return employees department name.
     */
    public String getDepartmentName(){
        return deptName;
    }

    /**Set new employee's department name.
     * @param empno new employee's department name.
     */
    public void setDepartmentName(String deptName){
        this.deptName = deptName;
    }


    /**Get an XML representation of the Employee
     * @param document document object.
     * @return element with XML data.
     */
    public Element getXML( Document document ){
        /**Create root element*/
        Element employee = document.createElement( "employee" );

        /**Create empno branch with value.*/
        Element temp = document.createElement( "empno" );
        temp.appendChild( document.createTextNode( String.valueOf(getEmployeeNo()) ) );
        employee.appendChild( temp );

        /**Create mgr branch with value and manager's name as attribute.*/
        temp = document.createElement( "mgr" );
        temp.setAttribute("mgrname", getManagerName() );
        temp.appendChild( document.createTextNode( String.valueOf(getManager()) ) );
        employee.appendChild( temp );

        /**Create deptno branch with value and department's name as attribute.*/
        temp = document.createElement( "deptno" );
        temp.setAttribute("deptname", getDepartmentName() );
        temp.appendChild( document.createTextNode( String.valueOf(getDepartmentNo()) ) );
        employee.appendChild( temp );

        /**Create ename branch with value.*/
        temp = document.createElement( "ename" );
        temp.appendChild( document.createTextNode( getEmployeeName() ) );
        employee.appendChild( temp );

        /**Create job branch with value.*/
        temp = document.createElement( "job" );
        temp.appendChild( document.createTextNode( getJob() ) );
        employee.appendChild( temp );

        /**Create salary branch with value.*/
        temp = document.createElement( "sal" );
        temp.appendChild( document.createTextNode( String.valueOf(getSalary()) ) );
        employee.appendChild( temp );

        /**Create commitee branch with value.*/
        temp = document.createElement( "comm" );
        temp.appendChild( document.createTextNode( String.valueOf(getCommisions()) ) );
        employee.appendChild( temp );

        /**Create hiredate branch with value.*/
        temp = document.createElement( "hiredate" );
        temp.appendChild( document.createTextNode( String.valueOf(getHireDate()) ) );
        employee.appendChild( temp );

        /** Return employee element*/
        return employee;
    }
}
